<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 过滤器的调用  |  -->
      <div>{{mydata | capitalize}}</div>
      <div>{{tname | capitalize}}</div>
      <div>{{num | cheng |two }}</div>
    </div>
    <script src="vue.js"></script>
    <script>
      // 首字母大写的过滤器
      Vue.filter('capitalize', function(value) {
        if (!value) return ''
        value = value.toString()
        return value.charAt(0).toUpperCase() + value.slice(1)
      })
      var vm = new Vue({
        el: '#app',
        data() {
          return {
            mydata: 'john',
            tname: 'anning',
            num: 127.99238213
          }
        },
        directives: {},
        components: {},
        filters: {
          two: function(value) {
            return value.toFixed(2)
          },
          cheng: function(value) {
            return value * 10
          }
        }
      })
    </script>
  </body>
</html>
